load(
    "@gz//bazel/skylark:build_defs.bzl",
    "GZ_FEATURES",
    "GZ_ROOT",
    "GZ_VISIBILITY",
    "cmake_configure_file",
    "gz_export_header",
    "gz_include_header",
)
load(
    "@gz//bazel/lint:lint.bzl",
    "add_lint_tests",
)

package(
    default_applicable_licenses = [GZ_ROOT + "common:license"],
    features = GZ_FEATURES,
)

# Configuration for UNIX
RMT_ENABLED = 1

RMT_USE_TINYCRT = 0

RMT_USE_CUDA = 0

RMT_USE_D3D11 = 0

RMT_USE_OPENGL = 1

RMT_USE_METAL = 0

cmake_configure_file(
    name = "remotery_config",
    src = "src/RemoteryConfig.h.in",
    out = "include/RemoteryConfig.h",
    cmakelists = ["CMakeLists.txt"],
    defines = [
        "RMT_ENABLED=%d" % RMT_ENABLED,
        "RMT_USE_TINYCRT=%d" % RMT_USE_TINYCRT,
        "RMT_USE_CUDA=%d" % RMT_USE_CUDA,
        "RMT_USE_D3D11=%d" % RMT_USE_D3D11,
        "RMT_USE_OPENGL=%d" % RMT_USE_OPENGL,
        "RMT_USE_METAL=%d" % RMT_USE_METAL,
    ],
    visibility = ["//visibility:private"],
)

public_headers_no_gen = [
    "include/gz/common/Profiler.hh",
]

sources = [
    "src/Profiler.cc",
    "src/RemoteryProfilerImpl.cc",
]

gz_export_header(
    name = "include/gz/common/profiler/Export.hh",
    export_base = "GZ_COMMON_PROFILER",
    lib_name = "gz-common-profiler",
    visibility = ["//visibility:private"],
)

gz_include_header(
    name = "profiler_hh_genrule",
    out = "include/gz/common/profiler.hh",
    hdrs = public_headers_no_gen + [
        "include/gz/common/profiler/Export.hh",
    ],
)

public_headers = public_headers_no_gen + [
    "include/gz/common/profiler/Export.hh",
    "include/gz/common/profiler.hh",
]

private_headers = [
    "src/ProfilerImpl.hh",
    "src/RemoteryProfilerImpl.hh",
    "include/RemoteryConfig.h",
]

cc_library(
    name = "remotery",
    srcs = ["src/Remotery/lib/Remotery.c"],
    hdrs = ["src/Remotery/lib/Remotery.h"],
    includes = ["src/Remotery/lib"],
)

cc_library(
    name = "profiler",
    srcs = sources,
    hdrs = public_headers + private_headers,
    defines = [
        "GZ_PROFILER_ENABLE=1",
        "GZ_PROFILER_REMOTERY=1",
    ],
    includes = ["include"],
    visibility = GZ_VISIBILITY,
    deps = [
        GZ_ROOT + "common",
        ":remotery",
    ],
)

cc_test(
    name = "Profiler_Disabled_TEST",
    srcs = ["src/Profiler_Disabled_TEST.cc"],
    copts = ["-Wno-macro-redefined"],
    defines = [
        "GZ_PROFILER_ENABLE=0",
        "GZ_PROFILER_REMOTERY=0",
    ],
    deps = [
        ":profiler",
        "@gtest",
        "@gtest//:gtest_main",
    ],
)

cc_test(
    name = "Profiler_Remotery_TEST",
    srcs = ["src/Profiler_Remotery_TEST.cc"],
    deps = [
        ":profiler",
        "@gtest",
        "@gtest//:gtest_main",
    ],
)

add_lint_tests()
